using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
using Models;
using OfficeOpenXml;

namespace Helper
{
    public class ExcelHelper
    {
        ///
        public static byte[] MakeExcel(Dictionary<string, Dictionary<string, string>> inDic)
        {
            using (ExcelPackage package = new ExcelPackage())
            {
                foreach (var item in inDic)
                {
                    var worksheet = package.Workbook.Worksheets.Add(item.Key);
                    foreach (var value in item.Value)
                    {
                        var keyList = value.Key.Split('|');
                        var row = Convert.ToInt32(keyList[0]);
                        var col = Convert.ToInt32(keyList[1]);
                        worksheet.SetValue(row, col, value.Value);
                    }
                }
                return package.GetAsByteArray();
            }
        }
    }
}